import 'package:flutter/material.dart';

///代码清单2-6
///代码路径 lib/code2/second_page.dart
class FirstPage extends StatefulWidget {
  final String? title;

  const FirstPage({Key? key, this.title}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return FirstPageState();
  }
}

class FirstPageState extends State<FirstPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.green,
      appBar: AppBar(
        title: const Text("A首页面"),
      ),
      body: Center(
          child: Column(
        children: [
          //使用上一个页面传递的参数
          Text("${widget.title}"),
          ElevatedButton(
              onPressed: () {
                if (Navigator.of(context).canPop()) {
                  Navigator.of(context).pop();
                }
              },
              child: const Text("关闭当前页面")),
        ],
      )),
    );
  }
}
